<?php

declare(ENCODING = 'UTF-8');

/*                                                                        *
 * This script is part of the TYPO3 project - inspiring people to share!  *
 *                                                                        *
 * TYPO3 is free software; you can redistribute it and/or modify it under *
 * the terms of the GNU General Public License version 2 as published by  *
 * the Free Software Foundation.                                          *
 *                                                                        *
 * This script is distributed in the hope that it will be useful, but     *
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *	
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
 * Public License for more details.                                       *
 *                                                                        */	

/**
 * @package auxo
 * @subpackage test
 * @version $Id$
 */

/**	
 * The Hash Array Testcase
 *	
 * @package auxo
 * @subpackage test
 * @version $Id$	
 * @copyright Copyright belongs to the respective authors
 * @author AHN
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
 */
class  tx_auxo_HashArray_testcase extends PHPUnit_Framework_testcase  {
	/**
	 * Sets up a test enviroment of this testcase.
	 */
	public function setUp() {
	}
	
	/**
	 * Testcase: Create a new hash array
     * 
	 * @test
	 */
	public function testHashArrayIsAvailable() {
		$hash = new tx_auxo_HashArray();
		$this->AssertType('tx_auxo_HashArray', $hash);
	}
	
	/**
	 * Testcase: Create a new hash array and add values
     * 
	 * @test
	 */
	public function testAddValues() {
		$hash = new tx_auxo_HashArray();
		$hash->add('Berlin');
		$hash->add('London');
		debug($hash);
		$this->assertTrue($hash->has('Berlin'));
		$this->assertTrue($hash->has('London'));
	}

	/**
	 * Testcase: Create a new hash array via constructor 
     * 
	 * @test
	 */
	public function testCreateValuesWithConstructor() {
		$hash = new tx_auxo_HashArray(array('Berlin', 'London'));
		$this->assertEquals(2, count($hash));
		$this->assertTrue($hash->has('Berlin'));
		$this->assertTrue($hash->has('London'));
	}
		
	/**
	 * Testcase: Count hash entries 
     * 
	 * @test
	 */
	public function testCountHashEntries() {
		$hash = new tx_auxo_HashArray();
		$hash->add('Berlin');
		$hash->add('London');
		$hash->add('Hamburg');
		$this->assertEquals(3, count($hash));
	}

	/**
	 * Testcase: ensure that hash entries are unique
     * 
	 * @test
	 */
	public function testHashEntriesAreUnique() {
		$hash = new tx_auxo_HashArray();
		$hash->add('Berlin');
		$hash->add('London');
		$hash->add('London');
		$hash->add('London');		
		$this->assertTrue($hash->has('Berlin'));
		$this->assertTrue($hash->has('London'));
		$this->assertEquals(2, count($hash));
	}
	
	/**
	 * Testcase: Entry is removed from hash
     * 
	 * @test
	 */
	public function testHashEntryIsRemoved() {
		$hash = new tx_auxo_HashArray();
		$hash->add('Berlin');
		$hash->add('London');
		$this->AssertEquals(2, count($hash));
		$hash->remove('Berlin');
		$this->assertEquals(1, count($hash));
		$this->assertFalse($hash->has('Berlin'));
		$this->assertTrue($hash->has('London'));
	}	
	
	/**
	 * Tears down a created test enviroment of this testcase.
	 */
	public function tearDown() {
	}
}